define(function(require, exports, module) {
    var myPub = require('./public');

    var oWindow = $(window);
    var oWrap = $('.js_wrap'); 					// wrap 部分
    var oHeader = $('.js_headerBox'); 			// 头部
    var oFooter = $('.js_footer'); 				// 底部
    var oContain = $('.js_contain'); 			// 页面内容区域

    var giftTell = $('.js_tellOrNot'); 			// 礼品告不告诉
    var giftHour = $('.js_countHour'); 			// 倒计时的小时
    var giftMinute = $('.js_countMinute'); 		// 倒计时的分钟
    var giftSecond = $('.js_countSecond'); 		// 倒计时的秒数

    var giftShareFri = $('.js_shareToFriend'); 				 // 分享给微信好友
    var giftShareWe = $('.js_shareToFriendGroup');			 // 分享给微信朋友圈
    var oShareTo = $('.js_shareTo');			 			// 分享给微信朋友圈
    var oGoodsImgInfo = $('.js_goodsImgInfo');			 	// 显示礼物图片的容器
    var oShareGuide =$('.js_shareGuide');			 	 	// 指引界面
    var oWishMessage = $("textarea[name='wishMessage']");
    var psdScrollTap_timer = null;

    var resizeTimer = null;

    module.exports = {
        init: function(data) {
            $("textarea[name='wishMessage']").blur(function(){
                giftShareTa.validateWish();
            });
            giftShareTa.giftInit(true);

            giftShareTa.giftEventInit();
            giftShareTa.giftCountDown(data,giftHour,giftMinute,giftSecond,function(){});

            // 页面尺寸修改
            oWindow.on('resize', function() {
                if(resizeTimer) {
                    clearTimeout(resizeTimer)
                }
                resizeTimer = setTimeout(function() {
                    giftShareTa.giftInit(true);
                }, 400);

            });
        }

    };

    oWishMessage.blur(function () {
        clearTimeout(psdScrollTap_timer);
        psdScrollTap_timer = setTimeout(function () {
            window.scrollTo(0,document.documentElement.clientHeight);
        },100);
    });

    var giftShareTa = {
        giftInit: function(bOff) {
            if(bOff) {
                oContain.css({
                    'padding-top': oHeader.outerHeight(true)
                });
            }
        },
        //事件绑定
        giftEventInit: function() {
            //点击告不告诉Ta
            giftTell.find('p').hammer().on('tap', function() {
                var index = $(this).index();
                giftTell.find('p').removeClass('active').eq(index).addClass('active');
                index === 0 ? oGoodsImgInfo.addClass('active') : oGoodsImgInfo.removeClass('active');
            });

            oShareTo.hammer().on('tap', function () {
                oShareGuide.show();
            });
            oShareGuide.hammer().on('tap', function () {
                $(this).hide();
            })
        },
        //倒计时
        //totalTime:总秒数   hourObj:小时放置的对象  minuteObj:分钟放置的对象  secondObj:秒数放置的对象  fn:倒计完成的函数
        giftCountDown: function(totalTime, hourObj, minuteObj, secondObj, fn) {
            clearInterval(timer);
            var timer=setInterval(function() {
                var day=0,hour = 0,minute = 0,second = 0; //时间默认值
                if(totalTime > 0) {
                    day = Math.floor(totalTime / (60 * 60 * 24));
                    hour = Math.floor(totalTime / (60 * 60)) - (day * 24);
                    minute = Math.floor(totalTime / 60) - (day * 24 * 60) - (hour * 60);
                    second = Math.floor(totalTime) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
                }else{
                    clearInterval(timer);
                    secondObj.html('00');
                    if(fn)fn;
                    return;
                }
                if(hour <=9) hour = '0' + hour;
                if(minute <= 9) minute = '0' + minute;
                if(second <= 9) second = '0' + second;

                hourObj.html(hour);
                minuteObj.html( minute);
                secondObj.html(second);
                totalTime--;
            }, 1000);
        },
        validateWish:function(){
            var wishMessage = $("textarea[name='wishMessage']").val();
            if(wishMessage.length >30){
                myPub.TipLayer("祝福语不能超过30个字");
                $("textarea[name='wishMessage']").val("");
            }
        }
    }


})